package fs.example {
	import flash.display.Sprite;
	import fs.component.event.ComponentEvent;
	import fs.component.RadioButton;
	
	/**
	 * ...
	 * @author F.S.
	 */
	public class RadioButtonExample extends Sprite {
		private const lanDic:Object = { "简体中文": ["地球", "太阳", "月亮", "比邻星"],
										"繁體中文": ["地球", "太陽", "月亮", "比鄰星"],
										"English":["Earth", "Sun", "Moon", "Centaurus-α"],
										"日本語":["地球", "太陽", "月", "ケンタウルス座-α"]
										}
										
		private var _planetRadioBtns:Array;
		
		public function RadioButtonExample() {
			addLanguage();
			addPlanet();
		}
		
		private function addLanguage():void {
			var rb:RadioButton = new RadioButton();
			rb.x = rb.y = 100;
			addChild(rb);
			rb.groupName = "language";
			rb.title = "简体中文";
			rb.onChanged = onLanguageChanged;
			
			var rb2:RadioButton = new RadioButton();
			rb2.x = 100;
			rb2.y = 130;
			addChild(rb2);
			rb2.groupName = "language";
			rb2.title = "繁體中文";
			rb2.onChanged = onLanguageChanged;
			
			var rb3:RadioButton = new RadioButton();
			rb3.x = 100;
			rb3.y = 160;
			addChild(rb3);
			rb3.groupName = "language";
			rb3.title = "English";
			rb3.onChanged = onLanguageChanged;
			
			var rb4:RadioButton = new RadioButton();
			rb4.x = 100;
			rb4.y = 190;
			addChild(rb4);
			rb4.groupName = "language";
			rb4.title = "日本語";
			rb4.onChanged = onLanguageChanged;
			
			rb.isOn = true;
		}
		
		private function onLanguageChanged(e:ComponentEvent):void {
			var planetArr:Array = lanDic[(e.target as RadioButton).title];
			
			for (var index:String in _planetRadioBtns) {
				var rb:RadioButton = _planetRadioBtns[index];
				rb.title = planetArr[index];
			}
		}
		
		private function addPlanet():void {
			var rb:RadioButton = new RadioButton();
			rb.x = 200;
			rb.y = 100;
			addChild(rb);
			rb.groupName = "planet";
			rb.title = "地球";
			
			var rb2:RadioButton = new RadioButton();
			rb2.x = 200;
			rb2.y = 130;
			addChild(rb2);
			rb2.groupName = "planet";
			rb2.title = "火星";
			
			var rb3:RadioButton = new RadioButton();
			rb3.x = 200;
			rb3.y = 160;
			addChild(rb3);
			rb3.groupName = "planet";
			rb3.title = "金星";
			
			var rb4:RadioButton = new RadioButton();
			rb4.x = 200;
			rb4.y = 190;
			addChild(rb4);
			rb4.groupName = "planet";
			rb4.title = "水星";
			rb4.isEnabled = false;
			
			rb.isOn = true;
			
			_planetRadioBtns = [rb, rb2, rb3, rb4];
		}
	}

}